package lxt.service.impl;

import java.util.ArrayList;
import java.util.List;

import lxt.dao.CostAccidentDao;
import lxt.entity.CostAccident;
import lxt.service.CostAccidentService;
/**
 * 交通事故管理service
 * @author Lit
 *
 */
public class CostAccidentServiceImpl implements CostAccidentService {

	private CostAccidentDao costAccidentDao ;
	
	public boolean addCostAccident(CostAccident costAccident) throws Exception {
		this.costAccidentDao.save(costAccident);
		return true;
	}

	public boolean deleteCostAccident(String id) throws Exception {
		String[] delId = id.split(",");
		for(int i=0;i<delId.length;i++){
			String idstr = delId[i];
			this.costAccidentDao.delete(CostAccident.class, idstr);
		}
		return true;
	}

	public int loadAllCostAccidentCount(String truckId, String driverId) throws Exception {
		return this.costAccidentDao.loadAllCostAccidentCount(truckId, driverId);
	}

	public List<CostAccident> loadCostAccident(String truckId, String driverId,
			int offset, int length) throws Exception {
		List<Object> objects = this.costAccidentDao.loadAllCostAccident(truckId, driverId, offset, length);
		//定义要传出的List
		List<CostAccident> costAccidents = new ArrayList<CostAccident>();
		if(objects.size()>0){
			for(int i=0;i<objects.size();i++){
				Object[] ob = (Object[]) objects.get(i);
				CostAccident costAccident = (CostAccident) ob[0];
				costAccident.setDriverId((String) ob[1]);
				costAccidents.add(costAccident);
			}
		}
		return costAccidents;
	}

	public CostAccident loadCostAccidentById(String id) throws Exception {
		return (CostAccident) this.costAccidentDao.get(CostAccident.class, id);
	}

	public boolean updateCostAccident(CostAccident costAccident)
			throws Exception {
		this.costAccidentDao.update(costAccident);
		return true;
	}
	
	/**
	 * get set
	 */
	public CostAccidentDao getCostAccidentDao() {
		return costAccidentDao;
	}

	public void setCostAccidentDao(CostAccidentDao costAccidentDao) {
		this.costAccidentDao = costAccidentDao;
	}
}
